<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles"
	prefix="tiles"%>

<rich:panel header="#{messages['voucher.mgmt.label']}">
	<h:panelGrid>
		<h:outputText value="#{errorBean.errorMessage}" styleClass="error"></h:outputText>
	</h:panelGrid>
	
	<h:panelGrid width="100%">
		<h:panelGroup>
		    <h:outputText value="#{messages['voucher.entry.update.label']}" styleClass="sub_header" />
			<h:outputText value="*" styleClass="standardText_Mandatory" />
			<h:outputText value="#{messages['instruction']}" styleClass="standardText_Instruction" />
		</h:panelGroup>
	</h:panelGrid>
	
	<h:panelGrid>
		<t:selectOneRadio layout="lineDirection" styleClass="standardText" value="#{agentVoucherMgmtBean.voucherEntryType}" >
		   	<f:selectItems value="#{agentVoucherMgmtBean.selectVoucherEntryTypeList}"/>
		   	
		   	<a4j:support ajaxSingle="true" event="onclick" action="#{agentVoucherMgmtBean.refreshVoucherEntryAction}" actionListener="#{agentVoucherMgmtBean.refreshVoucherEntryActionEvent}" reRender="voucherEntryType,memberGrid,nonMemberGrid,guestGrid" ></a4j:support>
		   	
		</t:selectOneRadio> 
	</h:panelGrid>
	
	<h:panelGrid>
		<h:outputText id="voucherEntryType" value="#{agentVoucherMgmtBean.voucherEntryType}" styleClass="standardText_Label" />	
	</h:panelGrid>	
	
	<t:panelGrid id="memberGrid" rendered="#{agentVoucherMgmtBean.voucherEntryType=='Member'}" columns="2" columnClasses="standardTable_ColumnLeft_20,standardTable_ColumnLeft_80" width="100%">
		<h:outputText></h:outputText>
		<t:message for="memberNo" styleClass="error"></t:message>
		
		<h:panelGroup>
			<h:outputText value="*" styleClass="standardText_Mandatory" />
			<h:outputLabel for="memberNo" value="#{messages['voucher.member.no.label']}" styleClass="standardText_Label" />
		</h:panelGroup>
		<h:panelGroup>
			<t:selectOneMenu id="memberNo" styleClass="standardText" value="#{agentVoucherMgmtBean.member.memberId}" required="true">
				<f:selectItem itemLabel="#{messages['please.select']}" itemValue="" />
				<f:selectItems value="#{agentVoucherMgmtBean.selectMemberList}"/>
				<a4j:support ajaxSingle="true" event="onclick" reRender="agreementNo"></a4j:support>
			</t:selectOneMenu>
		</h:panelGroup>	
		
		<h:outputText></h:outputText>
		<t:message for="agreementNo" styleClass="error"></t:message>
		
		<h:panelGroup>
			<h:outputText value="*" styleClass="standardText_Mandatory" />
			<h:outputLabel for="agreementNo" value="#{messages['voucher.agreement.no.label']}" styleClass="standardText_Label" />
		</h:panelGroup>
		<h:panelGroup>
			<t:selectOneMenu id="agreementNo" styleClass="standardText" value="#{agentVoucherMgmtBean.agreement.agreementId}" required="true">
				<f:selectItem itemLabel="#{messages['please.select']}" itemValue="" />
				<f:selectItems value="#{agentVoucherMgmtBean.selectAgreementList}"/>
				<a4j:support ajaxSingle="true" event="onclick" reRender="agreementNo"></a4j:support>
			</t:selectOneMenu>
		</h:panelGroup>
		
		<h:outputText value="#{messages['voucher.agreement.date.label']}" styleClass="standardText_Label" />
		<h:outputText value="#{agentVoucherMgmtBean.agreement.agreetmentDate}" styleClass="standardText" >
			<f:convertDateTime pattern="dd/MM/yyyy" timeZone="Asia/Kuala_Lumpur"/>
		</h:outputText>
		
		<h:outputText value="#{messages['voucher.membership.type.label']}" styleClass="standardText_Label" />
		<h:outputText value="#{agentVoucherMgmtBean.agreement.membershipType}" styleClass="standardText" />
		
		<h:outputText value="#{messages['voucher.member.name.label']}" styleClass="standardText_Label" />
		<h:outputText value="#{agentVoucherMgmtBean.member.name}" styleClass="standardText" />
	</t:panelGrid>
	
	<t:panelGrid id="nonMemberGrid" rendered="#{agentVoucherMgmtBean.voucherEntryType=='Non-Member'}" columns="2" columnClasses="standardTable_ColumnLeft_20,standardTable_ColumnLeft_80" width="100%">
	    <h:outputText></h:outputText>
		<t:message for="prospect" styleClass="error"></t:message>
		
		<h:panelGroup>
			<h:outputText value="*" styleClass="standardText_Mandatory" />
			<h:outputLabel for="prospect" value="#{messages['voucher.prospect.label']}" styleClass="standardText_Label" />
		</h:panelGroup>
		<h:panelGroup>
			<t:selectOneMenu id="prospect" styleClass="standardText" value="#{agentVoucherMgmtBean.member.memberId}" required="true">
				<f:selectItem itemLabel="#{messages['please.select']}" itemValue="" />
				<f:selectItems value="#{agentVoucherMgmtBean.selectProspectList}"/>
				
				<a4j:support ajaxSingle="true" event="onclick" action="null" reRender="data" actionListener="#{agentVoucherMgmtBean.refreshVoucherEntryActionEvent}"></a4j:support>
				
			</t:selectOneMenu>
		</h:panelGroup>  
	</t:panelGrid>
	
	<t:panelGrid id="guestGrid" rendered="#{agentVoucherMgmtBean.voucherEntryType=='Guest'}" columns="2" columnClasses="standardTable_ColumnLeft_20,standardTable_ColumnLeft_80" width="100%">
		<h:outputText></h:outputText>
		<t:message for="guestIcNo" styleClass="error"></t:message>
		
		<h:panelGroup>
			<h:outputText value="*" styleClass="standardText_Mandatory" />
			<h:outputLabel for="guestIcNo" value="#{messages['voucher.entry.ic.no.label']}" styleClass="standardText_Label" />
		</h:panelGroup>
		<h:panelGroup>
			<t:inputText id="guestIcNo" required="true" size="50" maxlength="50" styleClass="standardText"  value="#{agentVoucherMgmtBean.guest.icNo}"></t:inputText>
			<h:commandButton value="#{messages['check']}" styleClass="button" actionListener="#{agentVoucherMgmtBean.refreshVoucherEntryActionEvent}">
				 <a4j:support ajaxSingle="true" event="onclick" reRender="data" ></a4j:support>
			</h:commandButton>
		</h:panelGroup>
		
		
		<h:outputText></h:outputText>
		<t:message for="guestName" styleClass="error"></t:message>
		
		<h:panelGroup>
			<h:outputText value="*" styleClass="standardText_Mandatory" />
			<h:outputLabel for="guestName" value="#{messages['voucher.entry.name.label']}" styleClass="standardText_Label" />
		</h:panelGroup>
		<t:inputText id="guestName" required="true" size="50" maxlength="50" styleClass="standardText" value="#{agentVoucherMgmtBean.guest.name}"></t:inputText>
	</t:panelGrid>
	
	<rich:spacer height="10"></rich:spacer>
	
	<h:panelGrid width="100%" columns="1">
		<h:panelGroup>
			<rich:dataTable id="data" var="voucherEntryDetail" value="#{agentVoucherMgmtBean.voucherEntryDetailList}" rows="20" width="99%">
				<rich:column style="text-align:center;width:5%;" >
					<f:facet name="header">
						<h:selectBooleanCheckbox id="chkAll" onclick="checkAll(this.form,this)" ></h:selectBooleanCheckbox>
					</f:facet>
					<h:selectBooleanCheckbox id="chk" value="#{voucherEntryDetail.markAsSelect}"></h:selectBooleanCheckbox>
				</rich:column>
				
				<rich:column style="text-align:center;width:20%;">
					<f:facet name="header">
						<h:outputText value="#{messages['voucher.no.column']}"></h:outputText>
					</f:facet>
					<h:outputText value="#{voucherEntryDetail.voucher.voucherNo}"></h:outputText>
				</rich:column>		
				
				<rich:column style="text-align:center;width:20%;">
					<f:facet name="header">
						<h:outputText value="#{messages['voucher.issue.date.column']}"></h:outputText>
					</f:facet>
					<h:outputText value="#{voucherEntryDetail.issueDate}">
						<f:convertDateTime pattern="dd/MM/yyyy" timeZone="Asia/Kuala_Lumpur"/>
					</h:outputText>
				</rich:column>
				
				<rich:column style="text-align:center;width:20%;">
					<f:facet name="header">
						<h:outputText value="#{messages['voucher.expiry.date.column']}"></h:outputText>
					</f:facet>
					<h:outputText value="#{voucherEntryDetail.voucher.expiryDate}">
						<f:convertDateTime pattern="dd/MM/yyyy" timeZone="Asia/Kuala_Lumpur"/>
					</h:outputText>
				</rich:column>
				
				<rich:column style="text-align:center;width:15%;">
					<f:facet name="header">
						<h:outputText value="#{messages['voucher.no.of.nights.column']}"></h:outputText>
					</f:facet>
					<h:outputText value="#{voucherEntryDetail.voucher.noOfNights}"></h:outputText>
				</rich:column>
				
				<rich:column style="text-align:center;width:15%;">
					<f:facet name="header">
						<h:outputText value="#{messages['voucher.no.of.person.column']}"></h:outputText>
					</f:facet>
					<h:outputText value="#{voucherEntryDetail.voucher.noOfPerson}"></h:outputText>
				</rich:column>
				
				<rich:column style="text-align:center;width:15%;">
					<f:facet name="header">
						<h:outputText value="#{messages['voucher.weekend.column']}"></h:outputText>
					</f:facet>
					<h:outputText value="#{voucherEntryDetail.weekendFlag}"></h:outputText>
				</rich:column>
			</rich:dataTable>
		</h:panelGroup>
		
		<rich:datascroller align="left"  for="data" maxPages="20" />
		
		<t:panelGrid columns="2" columnClasses="standardTable_ColumnLeft_20,standardTable_ColumnLeft_80" width="100%">
			<h:outputText></h:outputText>
			<t:panelGrid columns="2">
				<h:commandButton value="#{messages['assign.new.voucher']}" action="#{agentVoucherMgmtBean.navAddVoucherEntryAction}" styleClass="button">
				</h:commandButton>
				<h:commandButton value="#{messages['remove.assigned.voucher']}" onclick="#{messages['delete.msg.alert']}" styleClass="button" action="#{agentVoucherMgmtBean.deleteVoucherEntryAction}" actionListener="#{agentVoucherMgmtBean.deleteVoucherEntryActionEvent}"></h:commandButton>
			</t:panelGrid>
		</t:panelGrid>
	</h:panelGrid>
</rich:panel>	